/**
 * 
 */
package cs2340.spring13.team3.wheresmystuff.support;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import cs2340.spring13.team3.wheresmystuff.R;

/**
 * @author chronon
 * 
 */
public class ItemSearchDialog extends Dialog {
	private Button mSearchButton;
	private Button mCancelButton;
	private Button mClearButton;
	private EditText mSearchTag;
	private EditText mSearchName;
	private SearchDialogListener listener;
	private RadioGroup mLostOrFound;

	public ItemSearchDialog(Context context) {
		super(context);
	}

	public ItemSearchDialog(Context context, SearchDialogListener l) {
		super(context);
		this.listener = l;
	}

	/**
	 * @see android.app.Dialog#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_search);

		mSearchButton = (Button) findViewById(R.id.searchButton);
		mCancelButton = (Button) findViewById(R.id.cancelButton);
		mClearButton = (Button) findViewById(R.id.btn_clear);
		mSearchTag = (EditText) findViewById(R.id.tagsToSearch);
		mSearchName = (EditText) findViewById(R.id.nameToSearch);
		mLostOrFound = (RadioGroup) findViewById(R.id.lost_or_found);

		mSearchButton
				.setOnClickListener(new android.view.View.OnClickListener() {

					@Override
					public void onClick(View arg0) {
						String nameString = mSearchName.getText().toString();
						String tagString = mSearchTag.getText().toString();
						boolean isFound = true;
						switch (mLostOrFound.getCheckedRadioButtonId()) {
						case R.id.radio_found:
							isFound = true;
							break;
						default:
							isFound = false;
							break;
						}
						listener.onOkClick(nameString, tagString, isFound);
						dismiss();
					}
				});
		mCancelButton
				.setOnClickListener(new android.view.View.OnClickListener() {

					@Override
					public void onClick(View arg0) {
						cancel();
					}
				});
		mClearButton
				.setOnClickListener(new android.view.View.OnClickListener() {

					@Override
					public void onClick(View arg0) {
						listener.onOkClick("", "", null);
						dismiss();
					}
				});
	}

}
